package com.yunduan.management.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunduan.management.entity.JobMember;
import com.yunduan.management.entity.Members;
import com.yunduan.management.entity.Project;
import com.yunduan.management.service.JobMemberService;
import com.yunduan.management.service.ProjectService;
import com.yunduan.management.utils.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hy
 * @since 2020-11-27
 */
@RestController
@CrossOrigin
public class ProjectController {
    @Autowired
    private ProjectService projectService;
    @Autowired
    private JobMemberService jobMemberService;

    @GetMapping("/getProjectByName")
    public JSONObject getProjectByName(String name){
        QueryWrapper<Project> projectQueryWrapper = new QueryWrapper<>();
        projectQueryWrapper.eq("name",name);
        Project project = projectService.getOne(projectQueryWrapper);
        List<Members> jobMembers = jobMemberService.getMembersByProId(project.getId());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("project",project);
        jsonObject.put("jobMembers",jobMembers);
        return jsonObject;
    }

    @GetMapping("/getAllProject")
    public JsonObject getAllProject(){
        return new JsonObject().success(projectService.list());
    }
}

